package me.mcx.mcx.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import me.mcx.common.annotation.Log;
import me.mcx.common.core.controller.BaseController;
import me.mcx.common.core.domain.AjaxResult;
import me.mcx.common.core.page.TableDataInfo;
import me.mcx.common.enums.BusinessType;
import me.mcx.common.utils.poi.ExcelUtil;
import me.mcx.mcx.domain.McxMessage;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import me.mcx.mcx.service.IMcxMessageService;

/**
 * 消息信息Controller
 * 
 * @author mcx
 * @date 2024-09-22
 */
@RestController
@RequestMapping("/mcx/message")
public class McxMessageController extends BaseController
{
    @Autowired
    private IMcxMessageService mcxMessageService;

    /**
     * 查询消息信息列表
     */
    @PreAuthorize("@ss.hasPermi('mcx:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(McxMessage mcxMessage)
    {
        startPage();
        List<McxMessage> list = mcxMessageService.selectMcxMessageList(mcxMessage);
        return getDataTable(list);
    }

    /**
     * 导出消息信息列表
     */
    @PreAuthorize("@ss.hasPermi('mcx:message:export')")
    @Log(title = "消息信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, McxMessage mcxMessage)
    {
        List<McxMessage> list = mcxMessageService.selectMcxMessageList(mcxMessage);
        ExcelUtil<McxMessage> util = new ExcelUtil<McxMessage>(McxMessage.class);
        util.exportExcel(response, list, "消息信息数据");
    }

    /**
     * 获取消息信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('mcx:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mcxMessageService.selectMcxMessageById(id));
    }

    /**
     * 新增消息信息
     */
    @PreAuthorize("@ss.hasPermi('mcx:message:add')")
    @Log(title = "消息信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody McxMessage mcxMessage)
    {
        return toAjax(mcxMessageService.insertMcxMessage(mcxMessage));
    }

    /**
     * 修改消息信息
     */
    @PreAuthorize("@ss.hasPermi('mcx:message:edit')")
    @Log(title = "消息信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody McxMessage mcxMessage)
    {
        return toAjax(mcxMessageService.updateMcxMessage(mcxMessage));
    }

    /**
     * 删除消息信息
     */
    @PreAuthorize("@ss.hasPermi('mcx:message:remove')")
    @Log(title = "消息信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mcxMessageService.deleteMcxMessageByIds(ids));
    }
}
